<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

         <!--app-->
        <link rel="stylesheet" href="css/fonts/font-awesome.min.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/appcan.icon.css">
        <link rel="stylesheet" href="css/appcan.control.css">
        <link rel="stylesheet" href="css_sdk/css/main.css">
        <link rel="stylesheet" href="test_content/css/new_user.css">
        <link rel="stylesheet" href="assets/css/amazeui.min.css">
        <link rel="stylesheet" href="assets/css/app.css">
        <!--<script src="js/jquery-1.8.3.min.js"></script>--> 
        <script src="js/jquery-1.11.1.min.js"></script> 
        <script src="js/jquery.form.js"></script> 
        <style>
            .am-header-default {
                background-color: #eb1111;
            }
            .bc-btn {
                background-color: #eb1111;
            }
            .logo {
                background-image: url('images/logo.png');
            }
            .umw4 {
                min-width: 0em;
            }
            .text-r {
                text-align: right;
            }
            .bc-head {
                background-color: #eb1111;
            }
             .umh5 {
                min-height: 2.5em;
             }
             .divselect {
               float: left;
               margin-left: 0.5em;
             }
             select {
                /*Chrome和Firefox里面的边框是不一样的，所以复写了一下*/
                border: solid 1px #000;

                /*很关键：将默认的select选择框样式清除*/
                appearance:none;
                -moz-appearance:none;
                -webkit-appearance:none;

                /*在选择框的最右侧中间显示小箭头图片*/
                background: url("http://ourjs.github.io/static/2015/arrow.png") no-repeat scroll right center transparent;


                /*为下拉小箭头留出一点位置，避免被文字覆盖*/
                padding-right: 2em;
                 padding-left: 0.5em;
}

        </style>
</head>


<body class="um-vp bc-bg" >

 <div id="header" class="uh bc-text-head ub bc-head">
                <div class="nav-btn" id="nav-left" onclick="javascript:history.go(-1)">
                    <div class="fa fa-angle-left fa-2x"></div>
                </div>
                <h1 class="ut ub-f1 ulev-3 ut-s tx-c" tabindex="0">新会员录入</h1>
                <div class="nav-btn nav-bt" id="nav-right"></div>
 </div>
    
    
        <div class="ub ub-ver uinn-a1">
<!--            <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac">
                <div class="ulev-app1 umw4">
                    加盟店
                </div>
                <div class="ub ub-ac umh5 ub-f1 ">
                    <div class="uinput ub ub-f1 ub-pe">
                        <div id="username"></div>
                        <div id="user"></div>
                        <div style="margin-right:0.5em">张三</div>
                        <div>sj8763738</div>
                    </div>
                </div>
            </div>-->

             <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac umar-at1">
                <div class="ulev-app1 umw4" style="margin-right:1em">
                    会员名称
                </div>
                <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1">
                        <input id="member_name" placeholder="请输会员名称" type="text" class="ub-f1 text-r" >
                    </div>
                </div>
            </div>

            <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac umar-at1">
                <div class="ulev-app1 umw4">
                 会员等级
                </div>
                <div class="t-bla ub ub-f2 ub-pe tab_l bc-top">
                    <div class=" ub ub-f1 ub-pe  ub-ac" style="font-size: 0.9em !important;">
                        <select id="select_grade" onchange="loadlevel()">
                        </select> 
                   </div>   
                </div>                   
<!--                 <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1 ub-pe ub-ac">
                        <select id="select_grade">
                        </select> 
                        <div>请选择</div>
                        <div><img src="images/go.png" style="width:1.9em"></div>
                    </div>
                </div>-->
            </div>
             <div class="uba b-gra3 uc-a1 c-wh ub ub-ver uinn-a7  umar-at1">
                <div class="ulev-app1 umw4">
                    推荐会员：
                </div>
                
                <div style="float:left"> <div class="ub ub-ac umh5 ub-f1">
                        <div class="uinput ub ub-f1 ub-pe ub-ac" style="font-size: 0.9em !important;">
                        <select id="select_employee">
                            <option>请选择推荐人</option>
                        </select> 
                      
                      
                    </div>
                </div> </div>
                
                           
<!--                <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1 ub-pe ub-ac">
                        <select id="select_employee">
                        </select> 
                        <div>请选择</div>
                        <div><img src="images/go.png" style="width:1.9em"></div>
                    </div>
                </div>-->
            </div>
            
            <div class="uba b-gra3 uc-a1 c-wh ub ub-ver uinn-a7  umar-at1">
                <div class="ulev-app1 umw4">
                    分类名称：
                </div>
                <div id="className">
                    
                </div>
            </div>
            
            
<!--            <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac umar-at1">
                <div class="ulev-app1 umw4">
                    负责人
                </div>
                <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1">
                        <input id="responsible_user" placeholder="请输入负责人" type="text" class="ub-f1 text-r">
                    </div>
                </div>
            </div>            -->
            
             <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac umar-at1">
                <div class="ulev-app1 umw4" style="margin-right:1em">
                    电话号码
                </div>
                <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1">
                        <input id="phone" placeholder="请输入电话号码" type="text" class="ub-f1 text-r" maxlength="11">
                    </div>
                </div>
            </div>
            
              <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac umar-at1">
                <div class="ulev-app1 umw4">
                    上传证件照
                </div>
                <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1 ub-pe ub-ac">
                        <!--<input type="button" value="上传" style="width:4em;" onclick="changeUpFile()" />-->
                        <form id="saveHandleForm" action="" method="post" enctype="multipart/form-data">
                            <input type="file" style="padding-left: 2em;" id="fileToUpload" name="fileToUpload" onchange="changeUpFile()" >
                        </form>                        
                        <!--<div>立即上传</div>-->
                        <!--<div><img src="images/go.png" style="width:1.9em"></div>-->
                    </div>
                </div>
            </div>
            
             <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac umar-at1">
                <div class="ulev-app1 umw4" style="margin-right:1em">
                    身份证号码
                </div>
                <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1">
                        <input id="id_number" placeholder="请输入身份证号码" type="text" class="ub-f1 text-r" maxlength="18" >
                    </div>
                </div>
            </div>

            <div class="uba b-gra3 uc-a1 c-wh ub uinn-a7 ub-ac umar-at1">
                <div class="ulev-app1 umw4" style="margin-right:1em">
                    银行账号
                </div>
                <div class="ub ub-ac umh5 ub-f1">
                    <div class="uinput ub ub-f1 ">
                        <input id="bank_account" placeholder="请输入银行账号" type="text" class="ub-f1 text-r">
                    </div>
                </div>
            </div>


      

            
            <div class="uin uinn ub" style="margin-top:1em">
                         <div class="ub-f2"></div>
                         <div class="btn ub-f2 ub ub-ac bc-text-head ub-pc bc-btn uc-a1"  id="submit" onclick="click_sub()">
                             提　交
                         </div>
                         <div class="ub-f2"></div>
            </div>
          
        </div>
    <script>
//        var user=sessionStorage.getItem("username")+"-"+localStorage.getItem("user");//用户
        var username=sessionStorage.getItem("username")+"-"
        var user=localStorage.getItem("user");//用户
        var upload_img='';//上传图片名  
        //页面默认数据
        function view_load(){
            
//            loadlevel();
            $("#user").html(user);
            $("#username").html(username);
            $.ajax({
                type: 'POST',
                url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/HuiyuanManageWebService/GetProvinceCityAreaList" ,
                data: {"ID":user},
                success: function(data){  
                    var arrEmployee=eval(data[0]["EmployeeGrid"]);
                    var arrGrid=eval(data[0]["LevelGrid"]);
                    var grade_list=[]//等级
                    var employe_list= [];//账号
                    employe_list.push('<option value="">请选择</option>');
                    grade_list.push('<option value="">请选择</option>');
                    for(var i=0;i<arrEmployee.length;i++){ 
                        employe_list.push('<option value="'+arrEmployee[i].f1+'">'+arrEmployee[i].f2+'</option>');
                    }
                    for(var i=0;i<arrGrid.length;i++){ 
                        grade_list.push('<option value="'+arrGrid[i].f1+'">'+arrGrid[i].f2+'</option>');
                    }                    
//                    $("#select_employee").empty().html(employe_list.join(''));
                  $("#select_grade").empty().html(grade_list.join(''));
                                        
                },
                dataType: "json",
            }); 
            var htm='';
            $.ajax({
                type: 'POST',
		async:false,
		url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/HuiyuanManageWebService/GetUserItemList" ,
		data: {},
		success: function(data){
                    $.each(data[0]["ItemList"],function(idx,item){
                        htm=htm+'<div style="float:left">'+
                    '<label class="am-checkbox needsclick" style="width:6em"><input name="class" type="checkbox" value="'+item.f1+'" data-am-ucheck="" class="am-ucheck-checkbox"><span class="am-ucheck-icons"><i class="am-icon-unchecked"></i><i class="am-icon-checked"></i></span> '+item.f2+'</label>'+
                    '</div>';
                    });
		},
		dataType: "json",
            });
            $("#className").html(htm);
            
        }
        view_load();
        //提交
        function click_sub(){
            var grade= $("#select_grade").val();//会员等级
            var employee= $("#select_employee").val();//推荐账号
            var member_name=$("#member_name").val();//会员名称
//            var responsible_user=$("#responsible_user").val();//负责人
            var phone=$("#phone").val();//电话
            var id_number=$("#id_number").val();//身份证
            var bank_account=$("#bank_account").val();//银行账号

            var result='';
            var check_array=document.getElementsByName("class");
            for(var i=0;i<check_array.length;i++){
               if(check_array[i].checked==true){         
                  result=result+","+check_array[i].value;
               }
           }
           
           
           if(member_name==""){
                alert('请输入会员名称！');
                return;
            }  
           
            if(grade==""){
                alert('请选择会员等级！');
                return;
            }
            
            console.log(employee);
            if(employee=="请选择推荐账号"||employee==""||employee==null){
                alert('请选择推荐账号！');
                return;
            } 
            if(result==""){
               alert('请选择分类！');
               return;
           }else{
               result=result.substr(1);
           }
            
//            if(responsible_user==""){
//                alert('请输入负责人！');
//                return;                
//            }
            if(phone.length!=11){
                alert('请输入正确的电话号码！');
                return;                
            }   
//            if(upload_img==""){
//                alert('请上传证件照！');
//                return;                
//            }   
            if(id_number.length!=0&&id_number.length!=18){
                alert('请输入正确的身份证号码！');
                return;                
            }   
//            if(bank_account==""){
//                alert('请输入银行账号！');
//                return;                
//            }
            var json='[{"f2":"'+member_name+'", "f3":"'+user+'", "f4":"'+employee+'", "f5":"'+grade+'", "f6":"", "f7":"'+phone+'", "f8":"'+id_number+'", "f13":"'+upload_img+'", "f14":"'+bank_account+'","f16":"'+result+'"}]';
            $.ajax({
                type: 'POST',
                url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/HuiyuanManageWebService/SetAddNewEmployee" ,
                data: {"ID":user,"JSONData":json},
                success: function(data){ 
                    var result=data[0]["Result"];
                    if (result==1){
                        alert('添加成功！');
                        window.location.reload();
                    }else if(result==-9){
                        alert('手机号已经存在！');
                    }else{
                        alert('提交失败！');
                    }
                },
                dataType: "json",
            });                   
        } 
        //上传照片
        var changeUpFile = function(){
            //set action 
            $("#saveHandleForm").attr("action","http://101.200.158.44:80/CosmeticSunyuxiWebService/services/FileUploadWebService/fileSave");
            $("#saveHandleForm").ajaxForm({
		data:{
			"userCD":""
			,"ImgeType":"jpg"
			,"UploadType":"IDCard"
		}
		,timout:300000
		,contentType:"application/x-www-form-urlencoded; charset=utf-8"
		,success:function(saveResponse){					
			var data=eval(saveResponse);
                        upload_img=data[0].Result;
		},error:function(){
			alert("图片上传失败");		
		}
			
	}).submit();
			
    }
    
    function loadlevel(){
        
          var grade= $("#select_grade").val();//会员等级
          if(grade!=""){

                var strUserRole=localStorage.getItem("role");
                var strID=localStorage.getItem("user");
                 $.ajax({
                        type: 'POST',
                        async:false,
                        url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/HuiyuanManageWebService/GetParentList" ,
                        data: {"ID":strID,"Level":grade},
                        success: function(data){

                            var employe_list= [];//账号
//                            employe_list.push('<option value="">请选择推荐人</option>');
                            $.each(data[0]["ParentList"],function(idx,item){
                                 employe_list.push('<option value="'+item.f1+'">'+item.f2+'</option>');
                            });

                            $("#select_employee").empty().html(employe_list.join(''));
                        },
                        dataType: "json",
                    });
              
          }
        
        
          
    }
    
    
//       function loadparent(){
//        var ParentID=jQuery("#select_grade").val()
//         $.ajax({
//                type: 'POST',
//		async:false,
//		url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/HuiyuanManageWebService/GetJieDianStoreList" ,
//		data: {"ParentID":ParentID},
//		success: function(data){
//                    var employe_list= [];//账号
//                   $.each(data[0]["JieDianStoreList"],function(idx,item){
//                       employe_list.push('<option value="'+item.f1+'">'+item.f2+'</option>');
//                    });
//                     $("#select_employee").empty().html(employe_list.join(''));
//		},
//		dataType: "json",
//            });
//          
//    }
    
    </script>

</body>
</html>
